package actions;

import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.sql.RowSet;

import model.*;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import db.DbException;
import forms.ProcessNotStartedInsertForm;

public class ProcessNotStartedInsertAction extends Action {

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws DbException {

		// Cast the form
		ProcessNotStartedInsertForm iForm = (ProcessNotStartedInsertForm) form;
		
		// Insert the student
		try {
			Database.insertReviewer(iForm);
		} catch (ClassNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		
		HttpSession session = request.getSession();
		RowSet crsReviewers = (RowSet) session.getAttribute("crsReviewers");
		
		try {
			crsReviewers = Database.getAllReviewers();
		} catch (DbException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		// Store the RowSet in the request scope
		session.setAttribute("crsReviewers", crsReviewers);

		return mapping.findForward("success");
	}
}
